package pruebas;

import junit.framework.TestCase;
import negModel.*;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;


public class ClimaTest extends TestCase {
	
	Clima c;
	Element e;

	protected void setUp() throws Exception {
		super.setUp();
		c=new Clima(0.7,"Nublado");
		
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
	    DocumentBuilder loader = factory.newDocumentBuilder();
	    Document doc = loader.newDocument();
				
		e= doc.createElement("clima");
		
		e.setAttribute("coef", ""+ c.getCoeficiente());
		e.setAttribute("nombre", c.getNombre());
		
	}
	
	public void testCoeficiente(){
		assertEquals(0.7,c.getCoeficiente(),0.0);
		
	}
	
	public void testNombre(){
		assertEquals("Nombre","Nublado",c.getNombre());
		
	}
	
	public void testClima () {
		
		Clima c2=new Clima(e);
		
		assertEquals(c2.getCoeficiente(),Double.parseDouble(e.getAttribute("coef")),0.0);
		assertEquals(c2.getNombre(),e.getAttribute("nombre"));
	}
	
	public void testToXml () throws Exception {
		
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
	    DocumentBuilder loader = factory.newDocumentBuilder();
	    Document doc = loader.newDocument();
		
		e=c.toXml(doc);
		
		assertEquals(Double.parseDouble(e.getAttribute("coef")),c.getCoeficiente(),0.0);
		assertEquals(e.getAttribute("nombre"),c.getNombre());
	}

}
